﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// 用户类
/// </summary>
public class User
{
    DBControl dbcontrol = new DBControl();

    #region 用户登录
    /// <summary>
    /// 用户登录
    /// </summary>
    /// <param name="strUserName"></param>
    /// <param name="strPwd"></param>
    /// <returns>TRUE OR FALSE</returns>
    public bool UserLogin(string strUserName, string strPwd)
    {
        string strCMD = "SELECT * FROM tb_UserInfo"
            +" WHERE UserName='"+strUserName
            +"' AND UserPwd='"+strPwd+"'";
        SqlDataReader dr = dbcontrol.GetDataReader(strCMD);
        if (dr.Read())
        {
            return true;
        }
        else
        {
            return false;
        }
        dr.Close();
        dr.Dispose();
    }
    #endregion

    #region 判断用户名是否存在
    /// <summary>
    /// 判断用户名是否存在
    /// </summary>
    /// <param name="strUserName"></param>
    /// <returns>TRUE OR FALSE</returns>
    public bool IsExist(string strUserName)
    {
        string strCMD = "SELECT * FROM tb_UserInfo WHERE UserName='"+strUserName+"'";
        SqlDataReader dr = dbcontrol.GetDataReader(strCMD);
        if (dr.Read())
        {
            return true;
        }
        else
        {
            return false;
        }
        dr.Close();
        dr.Dispose();
    }
    #endregion

    #region 用户注册
    /// <summary>
    /// 用户注册
    /// </summary>
    /// <param name="strUserName"></param>
    /// <param name="strNickName"></param>
    /// <param name="strUserPwd"></param>
    /// <param name="strEmail"></param>
    /// <param name="strAddress"></param>
    /// <param name="strHomePage"></param>
    /// <param name="dtRegistDate"></param>
    /// <returns>iResult</returns>
    public int AddUser(string strUserName, string strNickName,
        string strUserPwd, string strEmail, string strAddress,
        string strHomePage, DateTime dtRegistDate)
    {
        string strCMD = "INSERT INTO tb_UserInfo(UserName,NickName,UserPwd,UserEmail,UserAddress,UserHomePage,RegistDate)"
            +" VALUES('"+strUserName+"','"+strNickName
            +"','"+strUserPwd+"','"+strEmail
            +"','"+strAddress+"','"+strHomePage
            +"','"+dbcontrol.DateTimeToString(dtRegistDate)+"')";
        int iResult = dbcontrol.SqlExecuteNonQuery(strCMD);
        return iResult;
    }
    #endregion
}
